{% extends "base.html" %}
{% block title %} Assessments | sh00t{% endblock %}
{% block page %}
<ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="/">Dashboard</a></li>
    <li class="breadcrumb-item active"><i class="fa fa-cube"></i> Assessments</li>
</ol>
<div class="row">
    <div class="col-lg-6">
        {% if not projects %}
            <b>No project found. <a href="/app/projects/new/">Create one</a></b>
        {% else %}
            <form role="form" method="post">
                {% if "success" == submitted %}
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="alert alert-info alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <i class="fa fa-info-circle"></i> Submitted
                            </div>
                        </div>
                    </div>
                {% endif %}
                <div class="form-group">
                    <label>Name</label>
                    <input class="form-control" name="name" autocomplete="off" />
                </div>
                <div class="form-group">
                    <label for="project">Project</label>
                    <select id="project" class="form-control" name="project">
                        {% for project in projects %}
                            <option value="{{ project.id }}">{{ project.name }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    {% if not methodologies_list %}
                        No Methodologies found. We suggest you to <a href="/app/methodology-masters/" target="_blank"> create one</a>.
                    {% endif %}
                </div>
                <div class="form-group">
                    {% if not modules %}
                        No Modules found. We suggest you to <a href="/app/module-masters/" target="_blank"> create one</a>.
                    {% endif %}
                </div>

                <div class="form-group">
                    {% if methodologies_list and modules %}
                        <b>Set up Flags from</b>
                        {% for methodology in methodologies_list %}
                            <div class="checkbox">
                                <h4>
                                    <label>
                                        <input type="checkbox" class="methodology" value="{{ methodology.name.split|join:'_' }}" />
                                        {{ methodology.name }}:
                                    </label>
                                </h4>
                            </div>
                            {% for module in modules %}
                                {% if module.methodology == methodology %}
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" value="{{ module.id }}" class="child-{{ methodology.name.split|join:'_'  }}" name="modules" />
                                            {{ module.name }}
                                        </label>
                                    </div>
                                {% endif %}
                            {% endfor %}
                            <br />
                        {% endfor %}
                    {% endif %}
                </div>
                <button type="submit" class="btn btn-primary">Submit</button>
                {% csrf_token %}
            </form>
        {% endif %}
    </div>
    <div class="col-lg-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title"><i class="fa fa-cube"></i> Recent Assessments</h4>
            </div>
            <div class="panel-body">
                {% if assessments %}
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover table-striped">
                            <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Project</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for assessment in assessments %}
                                    <tr>
                                        <td><a href="/app/assessment/{{ assessment.id }}/">{{ assessment.name }}</a></td>
                                        <td><a href="/app/assessment/{{ assessment.project.id}}/">{{ assessment.project.name }}</a></td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    <div class="text-right">
                        <a href="/app/assessments/all/">View All <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                {% else %}
                    <h5>No Assessments yet. Add one.</h5>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block extra_foot %}
<script src="/static/js/common-ajax.js"></script>
<script type="text/javascript">
    $('.methodology').on('change', function() {
        $('.child-'+$(this).val()).prop('checked', $(this).is(":checked"));
    });
</script>
{% endblock %}